#include<stdio.h>
#include<string.h>

int main()
{
 #if 0   
    /*字符数组 定义*/
    /*字符串是由字符构成的*/
    /*"hello world" = 'h', 'e', 'l', 'l','o'*/

    char array[32] = "hello world";
    //char nums[32] = {'h','e','l','l','o'};

    char args[32];
    args[0] = 'h';
    args[1] = 'e';
    args[2] = 'l';
    args[3] = 'l';
    args[4] = '0';

    char vals[] = "nihao hello welcome";

    /*打印*/
    printf("array = %s\n", array);


    /*字符串的末尾默认加上'\n'*/
    char buffer[] = "hello world";
    char nums[] = "hello worldd";
    int size = sizeof(buffer);
    printf("size is %d\n",size);

    /*计算字符串的长度*/
    int length = strlen(buffer); 
    printf("length is %d\n",length);


    /*
        四个常用的字符串函数：strlen,strcat,strcmp,strcpy
    */
    int cmp = strcmp(buffer,nums);
    printf("cmp = %d\n",cmp);

    /*ACII码*/
    /*总结：strcmp函数是比较字符串大小的函数。比较的是ASCII码*/

    /*任意输入一个字符串，和 一个字符。这个字符在字符串中出现几次？*/
    /*"hello world" 'l' -> 3次*/
#endif
#if 0
      /*""表示字符串。末尾默认加上\0. 如果超过自己的存储空间，会报错*/
      char buffer[] = "hello world world";
      /*如何查看buffer占用的内存大小*/
      int length = sizeof(buffer);
      printf("length:%d\n",length);

      printf("buffer:%s\n",buffer);
      /*strlen计算到第一个反斜杠零之前的所有字符数*/

      int size = strlen(buffer);
      printf("size:%d\n",size);
#endif

#if 0
        char buffer[10] = "nihao";
        char array[] = {'h','e','l','l','o'};

        int size = sizeof(array);
        int length = strlen(array);
        printf("size:%d,length:%d\n",size,length);

        int nums[] = {1,2,3,4,5};
        size = sizeof(nums);
        printf("size:%d\n",size);

        /*总结：strlen碰到\0就截止计算*/

        
#endif
#if 1
     /*字符数组的赋值*/
     char buffer[] = "nihao niubai";

     for (int idx = 0;idx < strlen(buffer); idx++)
     {
        printf("buffer[%d] = %c\n",idx,buffer[idx]);
     }
#endif
    return 0;
}